<template>
	<view class="content bg-white p-4">
		<view class="mb-2">
			<el-select v-model="form.Group_Type" clearable placeholder="请选择浏览区域">
				<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
				</el-option>
			</el-select>
			<el-button @click="Select" type="primary" style="margin-left: 10rpx;">查询</el-button>
		</view>
		<view class="flex align-center bg-grey justify-between p-2">
			<text class="font-weight-bold font-lg">我的浏览记录</text>
			<!-- <el-button @click="DeleteAll" type="danger">清空全部浏览记录</el-button> -->
		</view>
		<!-- <view v-for="(item,i) in tableData" :key="i" class="p-4 flex align-center my-2 hover">
			<view class="flex flex-column" style="text-align: end;">
				<text>{{item.Group_Browse_Date}}</text>
				<text>浏览类型:{{item.Group_Type=='0'?'采购大厅':'供应大厅'}}</text>
			</view>
			<view class="flex align-center flex-1 mx-2">
				<image style="width: 200rpx;height: 200rpx;border-radius: 20rpx;" src="@/static/icon/R-C.jpg" mode="">
				</image>
				<view class="flex flex-column ml-2">
					<text>商品类型:黑木耳</text>
					<text>商品名称:北货郎精装黑木耳1kg</text>
					<text>所属企业:西货郎</text>
				</view>
			</view>
			<view class="flex flex-column justify-between" style="height: 150rpx;">
				<el-button @click="goDetail(item)" class="mb-2" size="small" type="success">查看详情</el-button>
				<el-button style="margin-left: 0;" @click="Deletehistory(item)" size="small" type="danger">删除记录</el-button>
			</view>
		</view> -->
		<el-table :data="tableData" border style="width: 100%" :header-cell-style="{ 'text-align': 'center' }"
			:cell-style="{ 'text-align': 'center' }">
			<el-table-column label="商品图片">
				<template v-slot="{row}">
					<image v-if="row.Group_Type=='1'" style="width: 100rpx;height: 100rpx;" :src="Domain_IMG + row.Picture_URL" mode=""></image>
					<image v-else style="width: 100rpx;height: 100rpx;" src="@/static/icon/nopic.png" mode=""></image>
				</template>
			</el-table-column>
			<el-table-column label="商品名称">
				<template v-slot="{row}">
					<el-tooltip effect="dark" :content="row.Group_Name" placement="top">
						<view class="text-ellipsis w-100">
							<text>{{row.Group_Name}}</text>
						</view>
					</el-tooltip>
				</template>
			</el-table-column>
			<el-table-column label="商品价格">
				<template v-slot="{row}">
						<view class="text-ellipsis w-100">
							<text>￥{{row.Amount}}</text>
						</view>
				</template>
			</el-table-column>
			<el-table-column label="浏览区域">
				<template v-slot="{row}">
					<view class="text-ellipsis w-100">
						<text>{{row.Group_Type=='0'?'采购大厅':'供应大厅'}}</text>
					</view>
				</template>
			</el-table-column>
			<el-table-column label="浏览时间">
				<template v-slot="{row}">
					<el-tooltip effect="dark" :content="row.Group_Browse_Date" placement="top">
						<view class="text-ellipsis w-100">
							<text>{{row.Group_Browse_Date}}</text>
						</view>
					</el-tooltip>
				</template>
			</el-table-column>
			<el-table-column prop="User_Number" label="浏览人账号"></el-table-column>
			<el-table-column label="操作">
				<template v-slot="{row}">
					<view class="flex justify-center">
						<el-button :loading="loading" @click="goDetail(row)" size="small" type="primary"
							class="btns">查看</el-button>
						<el-button :loading="loading" @click="Deletehistory(row,1)" size="small" type="danger"
							class="btns">删除</el-button>
					</view>
				</template>
			</el-table-column>
		</el-table>
		<view class="flex justify-between">
			<view class="">

			</view>
			<el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
				:current-page="form.page" :page-sizes="[3,5,10,20]" :page-size="form.limit"
				layout="total, sizes, prev, pager, next, jumper" :total="total">
			</el-pagination>
		</view>
	</view>
</template>

<script>
	const app = getApp()
	import times from '@/static/js/utils.js'
	import {
		Message,
		MessageBox,
		Popconfirm
	} from "element-ui"
	import {
		GoodsFileInquiry,
		getInquiryIDOriginal,
		getEditAction
	} from "@/api/global.js"
	import {
		GroupBrowsingAll
	} from "@/api/group.js"
	export default {
		data() {
			return {
				Domain_IMG:app.globalData.Domain_IMG,
				ThemeColors: app.globalData.ThemeColors,
				form: {
					Group_Type: "", //空全部0是供应1是采购,
					User_Number: uni.getStorageSync('loginInfo').use,
					page: 1, //页数
					limit:5,//每页数据条数
					// App:true,
				},
				total: 1,
				tableData: [], // 表格数据
				loading: false,
				options:[{
					label:'全部浏览记录',
					value:''
				},{
					label:'采购大厅浏览记录',
					value:'0'
				},{
					label:'供应大厅浏览记录',
					value:'1'
				},]
			};
		},
		mounted() {
			this.getList(this.form)
		},
		methods: {
			handleCurrentChange(e) {
				this.form.page = e
				this.getList(this.form)
			},
			handleSizeChange(e) {
				this.form.page = 1
				this.form.limit = e
				this.getList(this.form)
			},
			Select(){
				this.getList(this.form)
			},
			async getList(data) {
				const res = await GroupBrowsingAll({
					data
				})
				if (res.redirect && res.redirect == 'REDIRECT') {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				} else if (res.Status == 'success') {
					console.log(res)
					this.tableData = res.tableData
					this.total = Number(res.limit)
				}
			},
			async goDetail(item) {
				console.log(item)
				if(item.Group_Type=='0'){
					uni.navigateTo({
						url:'/pages/detail/purchase-detail?Group_Seek_Purchase_SerialNumber='+item.Group_SerialNumber+'&Enterprise_Info_SerialNumber='+item.Group_Browse_Path.slice(109,124)
					})
				}else{
					uni.navigateTo({
						url:'/pages/detail/supply-detail?id='+item.Group_SerialNumber+'&enterprise='+item.Group_Browse_Path.slice(59,74)
					})
				}
			},
			async getOriginal(data) {
				this.loading = true
				const res = await getInquiryIDOriginal({
					data
				})
				console.log(res)
				if (res.redirect && res.redirect == 'REDIRECT') {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}
				res[0].Row_Status = '1'
				let Data = {
					Data: JSON.stringify({
						Modify: {
							group_browsing_info: res
						},
					}),
					token: uni.getStorageSync('loginInfo').token,
				}
				this.getEdit(Data)
			},
			async getEdit(data) {
				const res = await getEditAction({
					data
				})
				if (res.redirect && res.redirect == 'REDIRECT') {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				} else if (res.Status == 'success') {
					Message({
						type: 'success',
						message: '已删除该条浏览记录'
					})
					this.loading = false
					this.getList(this.form)
				}
			},
			async Deletehistory(item) {
				MessageBox('此操作将删除该条浏览记录', '是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					console.log(1)
					let data = {
						Data: 'group_browsing_info',
						Primary_Key_Name: 'Group_Browse_SerialNumber',
						Primary_Key: item.Group_Browse_SerialNumber,
						isNullEnterprise: true
					}
					console.log(data)
					this.getOriginal(data)
				}).catch(() => {
					Message({
						type: 'warning',
						message: '已取消'
					})
				})
			},
			DeleteAll() {
				MessageBox('此操作将删除所有浏览记录', '是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					console.log(2)
				}).catch(() => {
					Message({
						type: 'warning',
						message: '已取消'
					})
				})
			}
		}
	}
</script>

<style lang="scss">
	.hover {
		cursor: pointer;
		background-color: rgb(255, 245, 244);
	}

	.hover:hover {
		box-shadow: 0 0 10rpx rgba(0, 0, 0, .3);
	}
</style>